<?php

namespace app\admin\model;

use think\Model;

class CashCodeRule extends Model
{
    // 表名
    protected $name = 'cash_code_rule';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'category_text',
        'status_text'
    ];
    

    
    public function getCategoryList()
    {
        return ['无限制' => __('无限制'),'关键字限制' => __('关键字限制'),'日期限制' => __('日期限制'),'金额限制' => __('金额限制')];
    }     

    public function getStatusList()
    {
        return ['normal' => __('Normal'),'deleted' => __('Deleted'),'' => __('')];
    }     


    public function getCategoryTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['category'];
        $list = $this->getCategoryList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
